const EXTENSION_ID = "viecalendar@soddino.net";
const DB_FILENAME = "viecalendar.sqlite";
const RS_FILENAME = "viecalendar.properties";
const CI = Components.interfaces;
const CC = Components.classes;
const BUNDLE = getBundle("chrome://viecalendar/locale/" + RS_FILENAME);

function getExtensionManager() {
	return CC["@mozilla.org/extensions/manager;1"].getService(CI.nsIExtensionManager);
}

function getStorageService() {
	return CC["@mozilla.org/storage/service;1"].getService(CI.mozIStorageService);
}

function getDbFile() {
	var extensionManager = getExtensionManager();
	var installLocation = extensionManager.getInstallLocation(EXTENSION_ID);
	var file = installLocation.getItemLocation(EXTENSION_ID);
	file.append("chrome");
	file.append("data");
	file.append(DB_FILENAME);

	return file;
}

function formatString(text) {
	for (i = 1; i < arguments.length; i++) {
		text = text.replace(new RegExp("\\{" + i + "\\}", "g"), arguments[i]);
	}

	return text;
}

function getString(name, params) {
    if(params) {
        return BUNDLE.formatStringFromName(name, params, params.length); 
    }
    
    return BUNDLE.GetStringFromName(name);
}

function getBundle(url) {
    var bundleService = CC["@mozilla.org/intl/stringbundle;1"].getService(CI.nsIStringBundleService);
    
	var bundle = bundleService.createBundle(url);
        
	return bundle;
}
